#include "utils.h"
#include <experimental\filesystem>

namespace filesystem =std::experimental::filesystem;
using std::cout;
using std::endl;
using cv::Mat;
namespace chrono = std::chrono;

void Utils::save_face_image(Mat face_img, Mat body_img, const std::string& person_name, const std::string& file_path)
{
	filesystem::path lpath(file_path);
	if (!filesystem::exists(lpath))
		filesystem::create_directories(lpath);

	auto time_now = chrono::time_point_cast<chrono::milliseconds>(chrono::system_clock::now());
	std::time_t tt = chrono::system_clock::to_time_t(time_now);
	std::tm tm = *std::localtime(&tt);

	auto diff = chrono::duration_cast<chrono::milliseconds>(time_now.time_since_epoch()).count();
	int const msecs = diff % 1000;

	char mbstr[100] = { 0 };
	std::strftime(mbstr, sizeof(mbstr), "%Y%m%d%H%M%S", std::localtime(&tt));

	std::string time_str(mbstr);
	char mbstr_msec[4];
	sprintf(mbstr_msec, "%d", msecs);
	time_str += mbstr_msec;

	imwrite(file_path + time_str + "_" + person_name + "_face.jpg", face_img);
	imwrite(file_path + time_str + "_" + person_name + "_body.jpg", body_img);

	/*fstream fout(file_path+"/label.txt", ios::app);
	fout << time_str + ".jpg" << " " << person_name << endl;
	fout.close();*/
}
